<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="back iconfont icon-xiangzuo1" @tap="backPage"></view>
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">求购车源</view>
		</view>	
		<view class="bg_box">
			<image class="bg01" :src="getImgSrc('/static/bg05.png')" mode="widthFix"></image>
			<view class="bg_content">
				
				<view class="details_box">
					<view class="list">
						<textarea placeholder="请填写需要求购的车辆，以及具体内容..." placeholder-style="color:#B5B5B5" maxlength="130" v-model="content" />
					</view>
					<view class="list">
						<view class="name">品牌型号</view>
						<input type="text" v-model="brand_name" value="" placeholder="请输入品牌型号" />
					</view>
					<view class="list">
						<view class="name">期待价格</view>
						<input type="text" v-model="price_range" value="" placeholder="请输入期待价格" />
					</view>
					<view class="list">
						<view class="name">使用年限</view>
						<input type="text" v-model="age" value="" placeholder="请输入年限" />
						<picker mode="selector" :range="age_list" @change="onAge"> 
						</picker>
					</view>
					<view class="list">
						<view class="name">地区</view>
						<input type="text" @tap="openAddres" v-model="pickerText" value="" placeholder="请选择所在地" />
						<view class="arrow iconfont icon-xiangyou1" @tap="openAddres"></view>
					</view>
					<view class="list">
						<view class="name">公里数</view>
						<input type="text" v-model="mile" value="" placeholder="请输入公里数" />
					</view>
					<view class="list">
						<view class="name">颜色</view>
						<input type="text" v-model="color" value="" placeholder="请输入颜色" />
					</view>
					<view class="list">
						<view class="name">其他</view>
						<input type="text" v-model="other" value="" placeholder="请输入" />
					</view>
				</view>
				
				<view class="details_box">
					<view class="list">
						<view class="name">联系电话</view>
						<input type="text" v-model="phone" value="" placeholder="请输入联系号码" />
					</view>
				</view>
				
				<view class="details_box">
					<view class="details_title">求购图片</view>
					<view class="standing">
						<image :src="images" :style="{width: imageWidth}" mode="widthFix" @tap="up_img()"></image>
					</view>
					<!-- <view class="standing">
						<image src="../../static/car02.png" mode="widthFix"></image>
					</view> -->
				</view>	
				
				<view class="clear_box04"></view>
				
				<view class="confirm" @click="publish">确认发布</view>
				
			</view>
		</view>
		<simple-address ref="simpleAddress" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"themeColor="#333"></simple-address>
	</view>
</template>

<script>
	import simpleAddress from '@/components/simple-address/simple-address.vue';
	export default {
		data() {
			return {
				page:1,
				scrrol:false,
				info:'',
				defaultNum:'',
				cityPickerValueDefault: [0, 0, 1],
				age_list:['不限','1-3年', '3-6年', '6-10年', '10-15年','15年以上'],
				pickerText:'',
				content:'',
				brand_name:'',
				price_range:'',
				age:'',
				prov: '',
				city: '',
				area: '',
				mile:'',
				color:'',
				phone:'',
				images:this.getImgSrc('/static/car01.png'),
				other:'',
				imageWidth:'100%',
				is_vip:0,
			}
		},
		components: {
			simpleAddress
		},
		onLoad(e) {
			let that = this;
			this.loadData();
		},
		methods: {
			numberInputResult(e){
				console.log('结果--'+e)
			},
			setRule(e){
				let that = this;
				let index = e.currentTarget.dataset.index;
				that.flowList[index].tick = !that.flowList[index].tick
			},
			loadData() {
				let that = this;
				that.Net._get('auth/member/get_info', {}, res => {
					if (res.code == 1) {
						that.is_vip = res.data.is_vip;
					}
				});
			},
			onAge(e) {
			    this.age = this.age_list[e.detail.value];
			},
			openAddres() {
				this.cityPickerValueDefault = [0, 0, 1];
				this.$refs.simpleAddress.open();
			},
			onConfirm(e) {
				let that = this;
				let pickerText = e.label.split('-');
				that.prov = pickerText[0];
				that.city = pickerText[1];
				that.area = pickerText[2];
				if (pickerText[1] == '市辖区'){
					that.city = pickerText[0];
					that.pickerText = that.prov;
				}else{
					that.pickerText = that.prov + '-' + that.city ;
				}
			},
			up_img(e) {
				let that = this;
				uni.chooseImage({
					sizeType: ['original', 'compressed'], // 可选择原图或压缩后的图片
					sourceType: ['album', 'camera'], // 可选择性开放访问相册、相机
					success: function (res) {
						const temFilePath = res.tempFilePaths; // 图片选择完成后 获取该图片的路劲
						uni.uploadFile({
							url:that.Cfg.Setting.root + 'index/lb_upload', // 上传文件的Controller
							filePath: temFilePath[0], // 要上传的文件路径
							name:'file',
							success: (res) => {
								that.imageWidth = '35%';
								let img = JSON.parse(res.data)
								that.images = img.data;
							}
						})
					}
				});
			},
			publish(){
				let that = this;
				/* if(that.is_vip == 0){
					that.Msg.Fail('会员才可发布');
					return '';
				} */
				if (that.content == ''){
					that.Msg.Fail('请输入求购描述');
					return '';
				}
				if (that.phone == ''){
					that.Msg.Fail('请输入联系电话');
					return '';
				}
				if (that.images == this.getImgSrc('/static/car01.png')){
					that.images = '';
				}
				let params = {
					car_text: that.content,
					images: that.images,
					brand_name: that.brand_name,
					age: that.age,
					mile: that.mile,
					price_range: that.price_range,
					color: that.color,
					phone: that.phone,
					prov: that.prov,
					city: that.city,
					area: that.area,
					other:that.other,
				};
				that.Net._post('auth/index/buy_hand', params, res => {
					if (res.code == 1) {
						that.Msg.Success('发布成功', res => {
							uni.navigateBack({});
						});
					}
				});
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},

		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
		onReachBottom() {
		  var that = this;
		  that.page++;
		  // that.Net._get('shop_goods', {per_page:'10',page:that.page,}, res => {
		  //   if (res.code == 200) {
		  //     //console.log(res)
		  //     if (res.data.data == '') {
		  //       uni.showToast({
		  //         title: '已经是最后一页了',
		  //         duration: 2000,
		  //         icon: 'none'
		  //       });
		  //     } else {
		  //       that.info = that.info.concat(res.data.data); //将数据拼接在一起
		  //     }
		  //   } else if (res.code == 0) {
		  //     that.Msg.Success(res.msg, res => {});
		  //   }
		  // });
		},
	}
</script>

<style>
	
	.header{
		background-color: transparent !important;
		height: 18vw !important;
	}
	
	.header .text{
		background-color: transparent !important;
		color: #333 !important;
	}
	
	.header .back{
		color: #333 !important;
	}
	
	.scrrolHeader{
		background-color: #FFE6D0 !important;
	}
	
	.bg_box{
		width: 100%;
		position: relative;
	}
	
	.bg_box .bg01{
		width: 100%;
	}
	
	.bg_box .bg_content{
		width: 92%;
		position: absolute;
		left: calc(50% - 46%);
		top: calc(13.5vw + var(--status-bar-height));
		z-index: 98;
	}
	
	.details_box {
		width: 100%;
		margin-top: 4%;
		background-color: #fff;
		padding: 5vw 4%;
		border-radius: 3vw;
	}
	
	.details_boxNo{
		padding: 0vw 4%;
	}
	
	.details_box .details_title {
		font-size: 4.2vw;
		color: #333;
		font-weight: bold;
		margin-bottom: 5vw;
	}
	
	.details_box .input_box{
		width: 100%;
		display: flex;
		align-items: center;
		border-bottom: 2px solid #FC5D20;
		height: 15vw;
	}
	
	.details_box .input_box .m{
		font-size: 4vw;
		color: #333;
		margin-right: 1vw;
		font-weight: bold;
		margin-top: 2vw;
	}
	
	.details_box .input_box input{
		font-size: 7vw;
		color: #333;
		flex: 1;
		font-weight: bold;
	}
	
	.details_box .list {
		width: 100%;
		padding: 5vw 0;
		border-bottom: 1px solid #F3F3F3;
		display: flex;
		align-items: center;
	}
	
	.details_box .list .name {
		font-size: 4.2vw;
		font-weight: bold;
		color: #333;
		margin-right: 4vw;
	}
	
	.details_box .list .text {
		flex: 1;
		font-size: 3.5vw;
		color: #333;
		margin-right: 1vw;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}
	
	.details_box .list .text .i{
		width: 5vw;
		margin-right: 1vw;
	}
	
	.details_box .list .text .i image{
		width: 100%;
	}
	
	.details_box .list input {
		flex: 1;
		font-size: 3.5vw;
		color: #333;
		margin-right: 3vw;
		text-align: right;
		font-weight: bold;
	}
	
	.details_box .list .arrow {
		font-size: 3.5vw;
		color: #333;
	}
	
	.standing{
		width: 100%;
		margin-bottom: 3vw;
	}
	
	.standing image{
		width: 100%;
	}
	
	.standing .text{
		width: 100%;
		font-size: 3.8vw;
		color: #333;
		font-weight: bold;
		margin-top: 3vw;
		text-align: center;
	}
	
	.details_box .standing:nth-child(2){
		margin-top: 5vw;
	}
	
	
	
	
</style>
